*set the global for data folder (ISSP)
global path ...

*add a folder named "output" inside data folder

********************************************************************************
*DESCRIPTIVE ANALYSES
********************************************************************************

*Fig. 2: the evolution of subjective social status (on a scale from 0 to 100) by social classes 


clear
use "$path\DATASET_1987-2018_ready.dta"

sort YEAR COUNTRY class5
bys YEAR COUNTRY class5: egen tbmean_ycc5=mean (TOPBOT100) if AGE>=20 & AGE<=60


local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess tbmean_ycc5 YEAR if class5==1, sort lpattern (solid) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==2, sort lpattern (solid) lcolor(gray))(lowess tbmean_ycc5 YEAR if class5==3, sort lpattern (dash) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==4, sort lpattern (shortdash) lcolor(black)) (lowess tbmean_ycc5 YEAR if class5==5, sort lpattern (shortdash) lcolor(gray)) if COUNTRY==`i', graphregion(color(white)) legend(order(1 "Upper-middle class" 2 "Lower-middle class" 3 "Small business owners" 4 "Skilled working class" 5 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\lowess 5 classes_`i'.png", replace
}


********************************************************************************
*Figure A.1 (appendix): the evolution of subjective social status (on a scale from 0 to 100) by social classes

clear
use "$path\DATASET_1987-2018_ready.dta"

sort YEAR COUNTRY class5
bys YEAR COUNTRY class5: egen tbmean_ycc5=mean (TOPBOT100) if AGE>=20 & AGE<=60

local country 348  578 616 752 756 840 276 82601
foreach i of local country {
twoway (connected tbmean_ycc5 YEAR if class5==1, sort lpattern (solid) lcolor(black) msymbol(circle))(connected tbmean_ycc5 YEAR if class5==4, sort lpattern (dash) lcolor(black)msymbol(diamond)) (connected tbmean_ycc5 YEAR if class5==5, sort lpattern (shortdash) lcolor(black)msymbol(triangle)) if COUNTRY==`i', graphregion(color(white)) legend(order(1 "Upper-middle class" 2 "Skilled working class" 3 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2018) noextend)  xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("") scheme(s1mono) 
graph export "$path\output\connected_`i'.png", replace
}


********************************************************************************
*Figure A.2: the class gap in subjective social status (on a scale from 0 to 100), men only

clear
use "$path\DATASET_1987-2018_ready.dta"

bys YEAR COUNTRY: egen TOPBOT1=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==1) / (SEX01==1))  
bys YEAR COUNTRY: egen TOPBOT4=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==4) / (SEX01==1))
gen diff14= TOPBOT1 - TOPBOT4
bys YEAR COUNTRY: egen TOPBOT5=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==5) / (SEX01==1))
gen diff15= TOPBOT1 - TOPBOT5

local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess diff14 YEAR, sort lcolor(black) lpattern(dash)) (lowess diff15 YEAR, sort lcolor(black) lpattern(shortdash)) if COUNTRY==`i', graphregion(color(white)) legend(label(1 "Difference: upper-middle class - skilled working class") label (2 "Difference: upper-middle class - unskilled working class") cols(1) region(lstyle(none))) yscale(range(0 20)) ylabel(0 5 10 15 20, nogrid) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017)  ytitle("") xtitle("")
graph export "$path\output\difference_`i'.png", replace
}


********************************************************************************
*Figure A.3: the evolution of subjective social status (on a scale from 0 to 100) by education

clear
use "$path\DATASET_1987-2018_ready.dta"

sort YEAR COUNTRY ed_level
bys YEAR COUNTRY ed_level: egen tbmean_yc_ed=mean (TOPBOT100) if AGE>=20 & AGE<=60

local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess tbmean_yc_ed YEAR if ed_level==3, sort lpattern (solid) lcolor(black))(lowess tbmean_yc_ed YEAR if ed_level==2, sort lpattern (dash) lcolor(black)) (lowess tbmean_yc_ed YEAR if ed_level==1, sort lpattern (shortdash) lcolor(black)) if COUNTRY==`i', graphregion(color(white))  legend(label(1 "Tertiary university education") label(2 "Upper secondary and post-upper secondary education") label(3 "Less than upper secondary education") cols(1) nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\lowess ed_level `i'.png", replace
}


********************************************************************************
*Table A.1: number of observations with non-missing values in analytical sample of ISSP data rounds (ages 20-60)

clear
use "$path\DATASET_1987-2018_ready.dta"
tab country YEAR  if AGE>=20 & AGE<=60 & class5!=. & ed_level!=. & TOPBOT100!=. & SEX!=.


********************************************************************************
*Table A.2: Descriptive statistics of variables in analytical sample of ISSP data rounds (ages 20-60)

clear
use "$path\DATASET_1987-2018_ready.dta"

*select only years in which we have some observations with non missing subjective social status
bys COUNTRY YEAR: egen TOPBOT_MEAN= mean (TOPBOT)
gen TOPBOTSI=0
replace TOPBOTSI=1 if TOPBOT_MEAN>0 & TOPBOT_MEAN<10 

*subjective status mean / country
bys country: sum TOPBOT100 if AGE>=20 & AGE<=60 & TOPBOTSI==1

*status compared to the father
gen V67_100=V67
recode V67_100 (5=0) (4=25) (3=50) (2=75)(1=100)
bys country: sum V67_100 if AGE>=20 & AGE<=60 & TOPBOTSI==1

*class5
tab class5 country if AGE>=20 & AGE<=60 & TOPBOTSI==1, col

*ed_level
tab ed_level country if AGE>=20 & AGE<=60 & TOPBOTSI==1, col
tab ed_level1 country if AGE>=20 & AGE<=60 & TOPBOTSI==1, col

*sex
tab SEX01 country if AGE>=20 & AGE<=60 & TOPBOTSI==1, col

*sex
bys country: sum AGE if AGE>=20 & AGE<=60 & TOPBOTSI==1


********************************************************************************
*Figure A.2: the class gap in subjective social status (on a scale from 0 to 100), men only


clear
use "$path\DATASET_1987-2018_ready.dta"

bys YEAR COUNTRY: egen TOPBOT1=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==1) / (SEX01==1))  
bys YEAR COUNTRY: egen TOPBOT4=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==4) / (SEX01==1))
gen diff14= TOPBOT1 - TOPBOT4
bys YEAR COUNTRY: egen TOPBOT5=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==5) / (SEX01==1))
gen diff15= TOPBOT1 - TOPBOT5

local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess diff14 YEAR, sort lcolor(black) lpattern(dash)) (lowess diff15 YEAR, sort lcolor(black) lpattern(shortdash)) if COUNTRY==`i', graphregion(color(white)) legend(label(1 "Difference: upper-middle class - skilled working class") label (2 "Difference: upper-middle class - unskilled working class") cols(1) region(lstyle(none))) yscale(range(0 20)) ylabel(0 5 10 15 20, nogrid) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017)  ytitle("") xtitle("")
graph export "$path\output\difference_`i'.png", replace
}

********************************************************************************
*Figure W.2: subjective social status (on a scale from 0 to 100) by social class - men

clear
use "$path\DATASET_1987-2018_ready.dta"

sort YEAR COUNTRY class5
bys YEAR COUNTRY class5: egen tbmean_ycc5=mean (TOPBOT100) if AGE>=20 & AGE<=60 & SEX01==1


local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess tbmean_ycc5 YEAR if class5==1, sort lpattern (solid) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==2, sort lpattern (solid) lcolor(gray))(lowess tbmean_ycc5 YEAR if class5==3, sort lpattern (dash) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==4, sort lpattern (shortdash) lcolor(black)) (lowess tbmean_ycc5 YEAR if class5==5, sort lpattern (shortdash) lcolor(gray)) if COUNTRY==`i', graphregion(color(white)) legend(order(1 "Upper-middle class" 2 "Lower-middle class" 3 "Small business owners" 4 "Skilled working class" 5 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\lowess 5 classes_`i'MEN.png", replace
}


********************************************************************************
*Figure W.6: the evolution of variance in the subjective social status of three social classes (standard deviation on a scale from 0 to 100, evolution over time smoothened with lowess)  

clear
use "$path\DATASET_1987-2018_ready.dta"

bys YEAR COUNTRY: egen TOPBOT1=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==1) / (SEX01==1))  
bys YEAR COUNTRY: egen TOPBOT4=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==4) / (SEX01==1))
bys YEAR COUNTRY: egen TOPBOT5=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==5) / (SEX01==1))

sort YEAR COUNTRY
br YEAR COUNTRY class5 TOPBOT1 TOPBOT4 TOPBOT5

keep if country!=""
keep if class5!=.

bys YEAR COUNTRY class5: gen NUMBER=_n
keep if NUMBER==1

bys COUNTRY: egen stdevTOPBOT1=sd(TOPBOT1)
bys COUNTRY: egen stdevTOPBOT4=sd(TOPBOT4)
bys COUNTRY: egen stdevTOPBOT5=sd(TOPBOT5)
 
 
fre COUNTRY
gen numbercountry=COUNTRY
recode numbercountry (840=1)(82601=2)(276=3)(756=4)(752=5)(578=6)(616=7)(348=8)
label define numbercountry 1 "United States" 2 "Great Britain" 3 "Germany" 4 "Switzerland" 5 "Sweden" 6 "Norway" 7 "Poland" 8 "Hungary"
label values numbercountry numbercountry
fre numbercountry

list numbercountry country 
tab numbercountry, m
tab numbercountry class5

twoway (dot stdevTOPBOT1 numbercountry, sort mcolor(black*0.4)msymbol(O)) (dot stdevTOPBOT4 numbercountry, sort mcolor(black*0.65)msymbol(D))(dot stdevTOPBOT5 numbercountry, sort mcolor(black)msymbol(T)), graphregion(color(white)) legend(order(3 "Unskilled working class" 2 "Skilled working class" 1 "Upper-middle class" ) cols(1) region(lstyle(none) style(none))) xscale(range(1 8) noextend) xlabel(1 "United States" 2 "Great Britain" 3 "Germany" 4 "Switzerland" 5 "Sweden" 6 "Norway" 7 "Poland" 8 "Hungary", angle(90)) ytitle("") xtitle("") scheme(s2mono)
graph export "$path\output\stdev.png", replace


********************************************************************************
*Figure W.3: subjective social status (on a scale from 0 to 100) by social class - women

clear
use "$path\DATASET_1987-2018_ready.dta"

sort YEAR COUNTRY class5
bys YEAR COUNTRY class5: egen tbmean_ycc5=mean (TOPBOT100) if AGE>=20 & AGE<=60 & SEX01==0


local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess tbmean_ycc5 YEAR if class5==1, sort lpattern (solid) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==2, sort lpattern (solid) lcolor(gray))(lowess tbmean_ycc5 YEAR if class5==3, sort lpattern (dash) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==4, sort lpattern (shortdash) lcolor(black)) (lowess tbmean_ycc5 YEAR if class5==5, sort lpattern (shortdash) lcolor(gray)) if COUNTRY==`i', graphregion(color(white)) legend(order(1 "Upper-middle class" 2 "Lower-middle class" 3 "Small business owners" 4 "Skilled working class" 5 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\lowess 5 classes_`i'WOMEN.png", replace
}


********************************************************************************
*Figure W.8: Subjective social status (on a scale from 0 to 100) by educational level, men only

clear
use "$path\DATASET_1987-2018_ready.dta"

gen ed_level1=.
replace ed_level1=1 if DEGREE==0 | DEGREE==1 | DEGREE==2
replace ed_level1=2 if DEGREE==3
replace ed_level1=3 if DEGREE==5 

label variable ed_level1 "three levels for respondent education"
label define ed_level1 1 "No more than compulsory education" 2 "Upper-secondary education" 3 "Tertiary university education", replace
label value ed_level1 ed_level1
fre ed_level1

sort YEAR COUNTRY ed_level1
bys YEAR COUNTRY ed_level1: egen tbmean_yc_ed=mean (TOPBOT100) if AGE>=20 & AGE<=60 & SEX01==1


local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess tbmean_yc_ed YEAR if ed_level==3, sort lpattern (solid) lcolor(black))(lowess tbmean_yc_ed YEAR if ed_level==2, sort lpattern (dash) lcolor(black)) (lowess tbmean_yc_ed YEAR if ed_level==1, sort lpattern (shortdash) lcolor(black)) if COUNTRY==`i', graphregion(color(white))  legend(label(1 "Tertiary university education") label(2 "Upper secondary education") label(3 "Less than upper secondary education") cols(1) nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\lowess ed_level `i'.png", replace
}


********************************************************************************
*Figure W.9: gap in subjective social status (from 0 to 100) – holders of tertiary university education relative to holders of secondary education, men only

clear
use "$path\DATASET_1987-2018_ready.dta"

gen ed_level1=.
replace ed_level1=1 if DEGREE==0 | DEGREE==1 | DEGREE==2
replace ed_level1=2 if DEGREE==3
replace ed_level1=3 if DEGREE==5 

label variable ed_level1 "three levels for respondent education"
label define ed_level1 1 "No more than compulsory education" 2 "Upper-secondary education" 3 "Tertiary university education", replace
label value ed_level1 ed_level1
fre ed_level1

bys YEAR COUNTRY: egen TOPBOT1=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (ed_level1==1) / (SEX01==1))  
bys YEAR COUNTRY: egen TOPBOT2=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (ed_level1==2) / (SEX01==1))
bys YEAR COUNTRY: egen TOPBOT3=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (ed_level1==3) / (SEX01==1))
gen diff_ed= TOPBOT3 - TOPBOT2

local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess diff_ed YEAR, sort lpattern (solid) lcolor(black)) if COUNTRY==`i', graphregion(color(white))  legend(label(1 "Difference: tertiary univerity education - secondary education") nobox region(lstyle(none))) yscale(range(0 15)) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017) ylabel(0(5)15, nogrid) ytitle("") xtitle("")
graph export "$path\output\lowess ed_level `i'DIFFERENCE.png", replace
}


********************************************************************************
*Figure W.10: subjective social status (on a scale from 0 to 100) for each social class, men only. Classes defined without using information about partner’s occupation

clear
use "$path\DATASET_1987-2018_classnopart_ready.dta"

sort YEAR COUNTRY class5
bys YEAR COUNTRY class5: egen tbmean_ycc5=mean (TOPBOT100) if AGE>=20 & AGE<=60 & SEX01==1


local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess tbmean_ycc5 YEAR if class5==1, sort lpattern (solid) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==2, sort lpattern (solid) lcolor(gray))(lowess tbmean_ycc5 YEAR if class5==3, sort lpattern (dash) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==4, sort lpattern (shortdash) lcolor(black)) (lowess tbmean_ycc5 YEAR if class5==5, sort lpattern (shortdash) lcolor(gray)) if COUNTRY==`i', graphregion(color(white)) legend(order(1 "Upper-middle class" 2 "Lower-middle class" 3 "Small business owners" 4 "Skilled working class" 5 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "C:\Users\nvigna\switchdrive\PHD LAUSANNE\tesi\articolo 1\version définitive COMPARATIVE POLITICAL STUDIES\revision\nouveaus do-files\output\lowess 5 classes_`i'MEN.png", replace
}

drop tbmean_ycc5

********************************************************************************
*Figure W.11: subjective social status (on a scale from 0 to 100) for each social class, women only. Classes defined without using information about partner’s occupation

clear
use "$path\DATASET_1987-2018_classnopart_ready.dta"
sort YEAR COUNTRY class5
bys YEAR COUNTRY class5: egen tbmean_ycc5=mean (TOPBOT100) if AGE>=20 & AGE<=60 & SEX01==0


local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess tbmean_ycc5 YEAR if class5==1, sort lpattern (solid) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==2, sort lpattern (solid) lcolor(gray))(lowess tbmean_ycc5 YEAR if class5==3, sort lpattern (dash) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==4, sort lpattern (shortdash) lcolor(black)) (lowess tbmean_ycc5 YEAR if class5==5, sort lpattern (shortdash) lcolor(gray)) if COUNTRY==`i', graphregion(color(white)) legend(order(1 "Upper-middle class" 2 "Lower-middle class" 3 "Small business owners" 4 "Skilled working class" 5 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "C:\Users\nvigna\switchdrive\PHD LAUSANNE\tesi\articolo 1\version définitive COMPARATIVE POLITICAL STUDIES\revision\nouveaus do-files\output\lowess 5 classes_`i'WOMEN.png", replace
}


********************************************************************************
*Figure W.12: subjective social status (on a scale from 0 to 100) for each social class, men only. Classes defined without using information about partner’s occupation.

clear
use "$path\DATASET_1987-2018_classnopart_ready.dta"

bys YEAR COUNTRY: egen TOPBOT1=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==1) / (SEX01==1))  
bys YEAR COUNTRY: egen TOPBOT4=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==4) / (SEX01==1))
gen diff14= TOPBOT1 - TOPBOT4
bys YEAR COUNTRY: egen TOPBOT5=mean(TOPBOT100 / (AGE>=20) / (AGE<=60) / (class5==5) / (SEX01==1))
gen diff15= TOPBOT1 - TOPBOT5

local country 348 578 616 752 756 840 276 82601
foreach i of local country {
twoway (lowess diff14 YEAR, sort lcolor(black) lpattern(dash)) (lowess diff15 YEAR, sort lcolor(black) lpattern(shortdash)) if COUNTRY==`i', graphregion(color(white)) legend(label(1 "Difference: upper-middle class - skilled working class") label (2 "Difference: upper-middle class - unskilled working class") cols(1) region(lstyle(none))) yscale(range(0 20)) ylabel(0 5 10 15 20, nogrid) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017)  ytitle("") xtitle("")
graph export "C:\Users\nvigna\switchdrive\PHD LAUSANNE\tesi\articolo 1\version définitive COMPARATIVE POLITICAL STUDIES\revision\nouveaus do-files\output\difference_`i'.png", replace
}



********************************************************************************
*MULTIVARIATE ANALYSES
********************************************************************************

* Figure 3: predicted values and confidence intervals of subjective status (0-100) for a man aged 40 in the upper-middle (with tertiary education) or unskilled working class (without upper-secondary educ.)

*Figure W.4: predicted values of subjective status for a man aged 40 in the upper-middle class (with tertiary education) or the unskilled working class (without upper-secondary education)

*US
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==840 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\US_margins_lowess_confint.png", replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) ylabel(30(10)70, nogrid)xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid format(%9.0f)) ytitle("") xtitle("")
graph export "$path\output\US_margins_margins connected.png", replace


*relative trends:

keep if (class5==1 & ed_level==3) |(class5==4 & ed_level==2) | (class5==5 & ed_level==1)
save "$path\temporary estimates.dta", replace
use "$path\temporary estimates.dta", clear

sort year class5
by year: gen diff1=estimate[_n-1] - estimate
replace diff1=. if class5==5
by year: gen diff2=estimate[_n-2] - estimate
replace diff2=. if class5==4

twoway (lowess diff1 year if class5==4 & ed_level==2, sort lpattern (solid) lcolor(orange))(lowess diff2 year if class5==5 & ed_level==1, sort lpattern (solid) lcolor(red)), graphregion(color(white)) legend(order(2 "Difference: Upper-middle class - unskilled workers" 1 "Difference: Upper-middle class - skilled workers") cols(1) nobox region(lstyle(none))) yscale(range(5 25)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(5(5)25, nogrid) ytitle("") xtitle("") 
graph export "$path\output\US_margins_diff.png", replace


*GB
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==82601 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\GB_margins_lowess_confint.png", replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) ylabel(30(10)70, nogrid)xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid format(%9.0f)) ytitle("") xtitle("")
graph export "$path\output\GB_margins_margins connected.png", replace


*relative trends:
keep if (class5==1 & ed_level==3) |(class5==4 & ed_level==2) | (class5==5 & ed_level==1)
save "$path\temporary estimates.dta", replace
use "$path\temporary estimates.dta", clear

sort year class5
by year: gen diff1=estimate[_n-1] - estimate
replace diff1=. if class5==5
by year: gen diff2=estimate[_n-2] - estimate
replace diff2=. if class5==4

twoway (lowess diff1 year if class5==4 & ed_level==2, sort lpattern (solid) lcolor(orange))(lowess diff2 year if class5==5 & ed_level==1, sort lpattern (solid) lcolor(red)), graphregion(color(white)) legend(order(2 "Difference: Upper-middle class - unskilled workers" 1 "Difference: Upper-middle class - skilled workers") cols(1) nobox region(lstyle(none))) yscale(range(5 25)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(5(5)25, nogrid) ytitle("") xtitle("") 
graph export "$path\output\GB_margins_diff.png", replace


*DE
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==276 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\DE_margins_lowess_confint.png", replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) ylabel(30(10)70, nogrid)xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid format(%9.0f)) ytitle("") xtitle("")
graph export "$path\output\DE_margins_margins connected.png", replace


*relative trends:
keep if (class5==1 & ed_level==3) |(class5==4 & ed_level==2) | (class5==5 & ed_level==1)
save "$path\temporary estimates.dta", replace
use "$path\temporary estimates.dta", clear

sort year class5
by year: gen diff1=estimate[_n-1] - estimate
replace diff1=. if class5==5
by year: gen diff2=estimate[_n-2] - estimate
replace diff2=. if class5==4

twoway (lowess diff1 year if class5==4 & ed_level==2, sort lpattern (solid) lcolor(orange))(lowess diff2 year if class5==5 & ed_level==1, sort lpattern (solid) lcolor(red)), graphregion(color(white)) legend(order(2 "Difference: Upper-middle class - unskilled workers" 1 "Difference: Upper-middle class - skilled workers") cols(1) nobox region(lstyle(none))) yscale(range(5 25)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(5(5)25, nogrid) ytitle("") xtitle("") 
graph export "$path\output\DE_margins_diff.png", replace


*CH
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==756 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\CH_margins_lowess_confint.png", replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) ylabel(30(10)70, nogrid)xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid format(%9.0f)) ytitle("") xtitle("")
graph export "$path\output\CH_margins_margins connected.png", replace


*relative trends:
keep if (class5==1 & ed_level==3) |(class5==4 & ed_level==2) | (class5==5 & ed_level==1)
save "$path\temporary estimates.dta", replace
use "$path\temporary estimates.dta", clear

sort year class5
by year: gen diff1=estimate[_n-1] - estimate
replace diff1=. if class5==5
by year: gen diff2=estimate[_n-2] - estimate
replace diff2=. if class5==4

twoway (lowess diff1 year if class5==4 & ed_level==2, sort lpattern (solid) lcolor(orange))(lowess diff2 year if class5==5 & ed_level==1, sort lpattern (solid) lcolor(red)), graphregion(color(white)) legend(order(2 "Difference: Upper-middle class - unskilled workers" 1 "Difference: Upper-middle class - skilled workers") cols(1) nobox region(lstyle(none))) yscale(range(5 25)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(5(5)25, nogrid) ytitle("") xtitle("") 
graph export "$path\output\CH_margins_diff.png", replace

*SE
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==752 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\SE_margins_lowess_confint.png", replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) ylabel(30(10)70, nogrid)xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid format(%9.0f)) ytitle("") xtitle("")
graph export "$path\output\SE_margins_margins connected.png", replace


*relative trends:
keep if (class5==1 & ed_level==3) |(class5==4 & ed_level==2) | (class5==5 & ed_level==1)
save "$path\temporary estimates.dta", replace
use "$path\temporary estimates.dta", clear

sort year class5
by year: gen diff1=estimate[_n-1] - estimate
replace diff1=. if class5==5
by year: gen diff2=estimate[_n-2] - estimate
replace diff2=. if class5==4

twoway (lowess diff1 year if class5==4 & ed_level==2, sort lpattern (solid) lcolor(orange))(lowess diff2 year if class5==5 & ed_level==1, sort lpattern (solid) lcolor(red)), graphregion(color(white)) legend(order(2 "Difference: Upper-middle class - unskilled workers" 1 "Difference: Upper-middle class - skilled workers") cols(1) nobox region(lstyle(none))) yscale(range(5 25)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(5(5)25, nogrid) ytitle("") xtitle("") 
graph export "$path\output\SE_margins_diff.png", replace


*NO
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==578 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\NO_margins_lowess_confint.png", replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) ylabel(30(10)70, nogrid)xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid format(%9.0f)) ytitle("") xtitle("")
graph export "$path\output\NO_margins_margins connected.png", replace


*relative trends:
keep if (class5==1 & ed_level==3) |(class5==4 & ed_level==2) | (class5==5 & ed_level==1)
save "$path\temporary estimates.dta", replace
use "$path\temporary estimates.dta", clear

sort year class5
by year: gen diff1=estimate[_n-1] - estimate
replace diff1=. if class5==5
by year: gen diff2=estimate[_n-2] - estimate
replace diff2=. if class5==4

twoway (lowess diff1 year if class5==4 & ed_level==2, sort lpattern (solid) lcolor(orange))(lowess diff2 year if class5==5 & ed_level==1, sort lpattern (solid) lcolor(red)), graphregion(color(white)) legend(order(2 "Difference: Upper-middle class - unskilled workers" 1 "Difference: Upper-middle class - skilled workers") cols(1) nobox region(lstyle(none))) yscale(range(5 25)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(5(5)25, nogrid) ytitle("") xtitle("") 
graph export "$path\output\NO_margins_diff.png", replace


*PO
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==616 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\PO_margins_lowess_confint.png", replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) ylabel(30(10)70, nogrid)xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid format(%9.0f)) ytitle("") xtitle("")
graph export "$path\output\PO_margins_margins connected.png", replace


*relative trends:
keep if (class5==1 & ed_level==3) |(class5==4 & ed_level==2) | (class5==5 & ed_level==1)
save "$path\temporary estimates.dta", replace
use "$path\temporary estimates.dta", clear

sort year class5
by year: gen diff1=estimate[_n-1] - estimate
replace diff1=. if class5==5
by year: gen diff2=estimate[_n-2] - estimate
replace diff2=. if class5==4

twoway (lowess diff1 year if class5==4 & ed_level==2, sort lpattern (solid) lcolor(orange))(lowess diff2 year if class5==5 & ed_level==1, sort lpattern (solid) lcolor(red)), graphregion(color(white)) legend(order(2 "Difference: Upper-middle class - unskilled workers" 1 "Difference: Upper-middle class - skilled workers") cols(1) nobox region(lstyle(none))) yscale(range(5 25)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(5(5)25, nogrid) ytitle("") xtitle("") 
graph export "$path\output\PO_margins_diff.png", replace


*HU
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==348 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(lowess estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path\output\HU_margins_lowess_confint.png", replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) ylabel(30(10)70, nogrid)xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid format(%9.0f)) ytitle("") xtitle("")
graph export "$path\output\HU_margins_margins connected.png", replace


*relative trends:
keep if (class5==1 & ed_level==3) |(class5==4 & ed_level==2) | (class5==5 & ed_level==1)
save "$path\temporary estimates.dta", replace
use "$path\temporary estimates.dta", clear

sort year class5
by year: gen diff1=estimate[_n-1] - estimate
replace diff1=. if class5==5
by year: gen diff2=estimate[_n-2] - estimate
replace diff2=. if class5==4

twoway (lowess diff1 year if class5==4 & ed_level==2, sort lpattern (solid) lcolor(orange))(lowess diff2 year if class5==5 & ed_level==1, sort lpattern (solid) lcolor(red)), graphregion(color(white)) legend(order(2 "Difference: Upper-middle class - unskilled workers" 1 "Difference: Upper-middle class - skilled workers") cols(1) nobox region(lstyle(none))) yscale(range(5 25)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(5(5)25, nogrid) ytitle("") xtitle("") 
graph export "$path\output\HU_margins_diff.png", replace


********************************************************************************
*Figure 4: subjective status of respondent’s job as compared to status of father’s job – for a man aged 40 in the upper-middle (with university education) or unskilled working class (without upper-secondary educ.) 

*US

estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

gen V67_100=V67
recode V67_100 (5=0) (4=25) (3=50) (2=75)(1=100)

quietly reg V67_100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==840 & AGE>=20 & AGE<=60
quietly margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(40 70)) ylabel(40(10)70, nogrid format(%9.0f)) xscale(range(1987 2010) noextend) xlabel(1987 1992 1999 2010) ytitle("") xtitle("")
graph export "$path.dta\output\status_comparison_father\\US_margins_margins connected.png", replace


*GB

estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

gen V67_100=V67
recode V67_100 (5=0) (4=25) (3=50) (2=75)(1=100)

quietly reg V67_100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==82601 & AGE>=20 & AGE<=60
quietly margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none)))yscale(range(40 70)) ylabel(40(10)70, nogrid format(%9.0f)) xscale(range(1987 2010) noextend) xlabel(1987 1992 1999 2009) ytitle("") xtitle("")
graph export "$path.dta\output\status_comparison_father\\GB_margins_margins connected.png", replace

*DE

estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

gen V67_100=V67
recode V67_100 (5=0) (4=25) (3=50) (2=75)(1=100)

quietly reg V67_100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==276 & AGE>=20 & AGE<=60
quietly margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(40 70)) ylabel(40(10)70, nogrid format(%9.0f)) xscale(range(1987 2010) noextend) xlabel(1987 1992 1999 2010) ytitle("") xtitle("")
graph export "$path.dta\output\status_comparison_father\\DE_margins_margins connected.png", replace

*CH

estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

gen V67_100=V67
recode V67_100 (5=0) (4=25) (3=50) (2=75)(1=100)

quietly reg V67_100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==756 & AGE>=20 & AGE<=60
quietly margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(40 70)) ylabel(40(10)70, nogrid format(%9.0f)) xscale(range(1987 2010) noextend) xlabel(1987 1992 1999 2009) ytitle("") xtitle("")
graph export "$path.dta\output\status_comparison_father\\CH_margins_margins connected.png", replace

*SE

estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

gen V67_100=V67
recode V67_100 (5=0) (4=25) (3=50) (2=75)(1=100)

quietly reg V67_100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==752 & AGE>=20 & AGE<=60
quietly margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(40 70)) ylabel(40(10)70, nogrid format(%9.0f)) xscale(range(1987 2010) noextend) xlabel(1987 1992 1999 2009) ytitle("") xtitle("")
graph export "$path.dta\output\status_comparison_father\\SE_margins_margins connected.png", replace

*NO

estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

gen V67_100=V67
recode V67_100 (5=0) (4=25) (3=50) (2=75)(1=100)

quietly reg V67_100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==578 & AGE>=20 & AGE<=60
quietly margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(40 70)) ylabel(40(10)70, nogrid format(%9.0f)) xscale(range(1987 2010) noextend) xlabel(1987 1992 1999 2009) ytitle("") xtitle("")
graph export "$path.dta\output\status_comparison_father\\NO_margins_margins connected.png", replace

*PO

estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

gen V67_100=V67
recode V67_100 (5=0) (4=25) (3=50) (2=75)(1=100)

quietly reg V67_100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==616 & AGE>=20 & AGE<=60
quietly margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(40 70)) ylabel(40(10)70, nogrid format(%9.0f)) xscale(range(1987 2010) noextend) xlabel(1987 1992 1999 2010) ytitle("") xtitle("")
graph export "$path.dta\output\status_comparison_father\\PO_margins_margins connected.png", replace

*HU

estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

gen V67_100=V67
recode V67_100 (5=0) (4=25) (3=50) (2=75)(1=100)

quietly reg V67_100 class5##YEAR i.SEX01 AGE i.ed_level if COUNTRY==348 & AGE>=20 & AGE<=60
quietly margins YEAR, at (AGE=40 SEX01=1) by (class5 ed_level) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path\temporary estimates.dta", replace)

use "$path\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class5
destring class5, replace
rename parm3 ed_level
destring ed_level, replace
rename parm5 year
destring year, replace


twoway (connected estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black) msymbol(circle) mcolor(black))(line min95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(line max95 year if class==1 & ed_level==3, sort lpattern (solid) lcolor(gray))(connected estimate year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(black) msymbol(triangle) mcolor(black))(line min95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray))(line max95 year if class==5 & ed_level==1, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Unskilled working class") nobox region(lstyle(none))) yscale(range(40 70)) ylabel(40(10)70, nogrid format(%9.0f)) xscale(range(1987 2009) noextend) xlabel(1987 1992 1999 2009) ytitle("") xtitle("")
graph export "$path.dta\output\status_comparison_father\\HU_margins_margins connected.png", replace


********************************************************************************
*Table A.3: linear regression on subjective social status (from 0 to 100)

clear
use "$path\DATASET_1987-2018_ready.dta"

gen period=.
replace period=1 if YEAR>=1987 & YEAR<=1999
replace period=2 if YEAR>=2000 & YEAR<=2005
replace period=3 if YEAR>=2006 & YEAR<=2011
replace period=4 if YEAR>=2012 & YEAR<=2017

tab YEAR period, m

label define period 1 "1987-1999" 2 "2000-2005" 3 "2006-2011" 4 "2012-2017"
label values period period

local country 840 
foreach i of local country {
quietly reg TOPBOT100 class5##period SEX01 AGE if COUNTRY==`i' & AGE>=20 & AGE<=60
outreg2 using regression_interactions.xls, replace ctitle(model `i') dec(2)
}

local country 82601 752 578 276 756 616 348
foreach i of local country {
quietly reg TOPBOT100 class5##period SEX01 AGE if COUNTRY==`i' & AGE>=20 & AGE<=60
outreg2 using regression_interactions.xls, append ctitle(model `i') dec(2)
}


********************************************************************************
*Figure W.1: the evolution of subjective social status (on a scale from 0 to 100) by social classes

clear
use "$path\DATASET_1987-2018_ready.dta"

local country 40 36 203 705 703 643
foreach i of local country {
twoway (lowess tbmean_ycc5 YEAR if class5==1, sort lpattern (solid) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==2, sort lpattern (solid) lcolor(gray))(lowess tbmean_ycc5 YEAR if class5==3, sort lpattern (dash) lcolor(black))(lowess tbmean_ycc5 YEAR if class5==4, sort lpattern (shortdash) lcolor(black)) (lowess tbmean_ycc5 YEAR if class5==5, sort lpattern (shortdash) lcolor(gray)) if COUNTRY==`i', graphregion(color(white)) legend(order(1 "Upper-middle class" 2 "Lower-middle class" 3 "Small business owners" 4 "Skilled working class" 5 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend)  xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "C:\Users\nvigna\switchdrive\PHD LAUSANNE\tesi\DATI\International Social Survey Program (ISSP)\dati in uso ISSP\output\10 TOPBOT plot_other countries\lowess 5 classes\lowess 5 classes_`i'.png", replace
}


********************************************************************************
*Figure W.5: predicted values and confidence intervals of subjective status (0-100) for a man aged 40 for three classes: upper-middle class, production workers or service workers 

*US
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class6##YEAR i.SEX01 AGE if COUNTRY==840 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class6) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates.dta", replace)

use "$path.dta\temporary estimates.dta", clear

br


split parm, p("." "#")
rename parm1 class6
destring class6, replace
rename parm3 year
destring year, replace


twoway (lowess estimate year if class6==1, sort lpattern (solid) lcolor(black))(lowess min95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess max95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess estimate year if class6==5, sort lpattern (dash) lcolor(black))(lowess min95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess max95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess estimate year if class6==6, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class6==6, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class6==6, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Production workers" 7 "Service workers") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("") 
graph export "$path.dta\output\class6\US_margins_lowess_confint.png", replace



*GB

clear
use "$path\DATASET_1987-2018_ready.dta"
estimate clear

quietly reg TOPBOT100 class6##YEAR i.SEX01 AGE if COUNTRY==82601 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class6) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates.dta", replace)

use "$path.dta\temporary estimates.dta", clear

br


split parm, p("." "#")
rename parm1 class6
destring class6, replace
rename parm3 year
destring year, replace

twoway (lowess estimate year if class6==1, sort lpattern (solid) lcolor(black))(lowess min95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess max95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess estimate year if class6==5, sort lpattern (dash) lcolor(black))(lowess min95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess max95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess estimate year if class6==6, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class6==6, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class6==6, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Production workers" 7 "Service workers") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("") 
graph export "$path.dta\output\class6\GB_margins_lowess_confint.png", replace


*HU

clear
use "$path\DATASET_1987-2018_ready.dta"
estimate clear

quietly reg TOPBOT100 class6##YEAR i.SEX01 AGE if COUNTRY==348 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class6) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates.dta", replace)

use "$path.dta\temporary estimates.dta", clear

br


split parm, p("." "#")
rename parm1 class6
destring class6, replace
rename parm3 year
destring year, replace


twoway (lowess estimate year if class6==1, sort lpattern (solid) lcolor(black))(lowess min95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess max95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess estimate year if class6==5, sort lpattern (dash) lcolor(black))(lowess min95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess max95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess estimate year if class6==6, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class6==6, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class6==6, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Production workers" 7 "Service workers") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("") 
graph export "$path.dta\output\class6\HU_margins_lowess_confint.png", replace


*PL

clear
use "$path\DATASET_1987-2018_ready.dta"
estimate clear

quietly reg TOPBOT100 class6##YEAR i.SEX01 AGE if COUNTRY==616 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class6) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates.dta", replace)

use "$path.dta\temporary estimates.dta", clear

br


split parm, p("." "#")
rename parm1 class6
destring class6, replace
rename parm3 year
destring year, replace


twoway (lowess estimate year if class6==1, sort lpattern (solid) lcolor(black))(lowess min95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess max95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess estimate year if class6==5, sort lpattern (dash) lcolor(black))(lowess min95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess max95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess estimate year if class6==6, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class6==6, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class6==6, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Production workers" 7 "Service workers") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("") 
graph export "$path.dta\output\class6\PL_margins_lowess_confint.png", replace


*NO

clear
use "$path\DATASET_1987-2018_ready.dta"
estimate clear

quietly reg TOPBOT100 class6##YEAR i.SEX01 AGE if COUNTRY==578 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class6) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates.dta", replace)

use "$path.dta\temporary estimates.dta", clear

br


split parm, p("." "#")
rename parm1 class6
destring class6, replace
rename parm3 year
destring year, replace


twoway (lowess estimate year if class6==1, sort lpattern (solid) lcolor(black))(lowess min95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess max95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess estimate year if class6==5, sort lpattern (dash) lcolor(black))(lowess min95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess max95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess estimate year if class6==6, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class6==6, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class6==6, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Production workers" 7 "Service workers") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("") 
graph export "$path.dta\output\class6\NO_margins_lowess_confint.png", replace


*SE

clear
use "$path\DATASET_1987-2018_ready.dta"
estimate clear

quietly reg TOPBOT100 class6##YEAR i.SEX01 AGE if COUNTRY==752 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class6) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates.dta", replace)

use "$path.dta\temporary estimates.dta", clear

br


split parm, p("." "#")
rename parm1 class6
destring class6, replace
rename parm3 year
destring year, replace


twoway (lowess estimate year if class6==1, sort lpattern (solid) lcolor(black))(lowess min95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess max95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess estimate year if class6==5, sort lpattern (dash) lcolor(black))(lowess min95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess max95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess estimate year if class6==6, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class6==6, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class6==6, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Production workers" 7 "Service workers") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("") 
graph export "$path.dta\output\class6\SE_margins_lowess_confint.png", replace


*CH

clear
use "$path\DATASET_1987-2018_ready.dta"
estimate clear

quietly reg TOPBOT100 class6##YEAR i.SEX01 AGE if COUNTRY==756 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class6) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates.dta", replace)

use "$path.dta\temporary estimates.dta", clear

br


split parm, p("." "#")
rename parm1 class6
destring class6, replace
rename parm3 year
destring year, replace


twoway (lowess estimate year if class6==1, sort lpattern (solid) lcolor(black))(lowess min95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess max95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess estimate year if class6==5, sort lpattern (dash) lcolor(black))(lowess min95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess max95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess estimate year if class6==6, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class6==6, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class6==6, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Production workers" 7 "Service workers") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("") 
graph export "$path.dta\output\class6\CH_margins_lowess_confint.png", replace


*DE

clear
use "$path\DATASET_1987-2018_ready.dta"
estimate clear

quietly reg TOPBOT100 class6##YEAR i.SEX01 AGE if COUNTRY==276 & AGE>=20 & AGE<=60
margins YEAR, at (AGE=40 SEX01=1) by (class6) post
parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates.dta", replace)

use "$path.dta\temporary estimates.dta", clear

br

split parm, p("." "#")
rename parm1 class6
destring class6, replace
rename parm3 year
destring year, replace


twoway (lowess estimate year if class6==1, sort lpattern (solid) lcolor(black))(lowess min95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess max95 year if class6==1, sort lpattern (solid) lcolor(gray))(lowess estimate year if class6==5, sort lpattern (dash) lcolor(black))(lowess min95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess max95 year if class6==5, sort lpattern (dash) lcolor(gray))(lowess estimate year if class6==6, sort lpattern (shortdash) lcolor(black))(lowess min95 year if class6==6, sort lpattern (shortdash) lcolor(gray))(lowess max95 year if class6==6, sort lpattern (shortdash) lcolor(gray)), graphregion(color(white)) legend(order(1 "Upper-middle class" 4 "Production workers" 7 "Service workers") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("") 
graph export "$path.dta\output\class6\DE_margins_lowess_confint.png", replace


********************************************************************************
*W.13: Predicted subjective social status for a men aged 40 earning the mean income of his class

*US
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level income if COUNTRY==840 & AGE>=20 & AGE<=60
margins class5#ed_level, at(AGE=40 SEX01=1) atmeans by (YEAR) post

parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates", replace)

use "$path.dta\temporary estimates", clear

br

split parm, p("." "#")
rename parm1 year
destring year, replace
rename parm3 class5
destring class5, replace
rename parm5 ed_level
destring ed_level, replace

twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess estimate year if class==4 & ed_level==2, sort lpattern (dash) lcolor(black)) (lowess estimate year if class==5 & ed_level==1, sort lpattern (dash) lcolor(gray)), graphregion(color(white)) legend(order(1 "upper-middle class" 2 "Skilled working class" 3 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path.dta\output\US_margins_lowessINCOME.png", replace


*GB
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level income if COUNTRY==82601 & AGE>=20 & AGE<=60
margins class5#ed_level, at(AGE=40 SEX01=1) atmeans by (YEAR) post

parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates", replace)

use "$path.dta\temporary estimates", clear

br

split parm, p("." "#")
rename parm1 year
destring year, replace
rename parm3 class5
destring class5, replace
rename parm5 ed_level
destring ed_level, replace

twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess estimate year if class==4 & ed_level==2, sort lpattern (dash) lcolor(black)) (lowess estimate year if class==5 & ed_level==1, sort lpattern (dash) lcolor(gray)), graphregion(color(white)) legend(order(1 "upper-middle class" 2 "Skilled working class" 3 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path.dta\output\GB_margins_lowessINCOME.png", replace


*DE
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level income if COUNTRY==276 & AGE>=20 & AGE<=60
margins class5#ed_level, at(AGE=40 SEX01=1) atmeans by (YEAR) post

parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates", replace)

use "$path.dta\temporary estimates", clear

br

split parm, p("." "#")
rename parm1 year
destring year, replace
rename parm3 class5
destring class5, replace
rename parm5 ed_level
destring ed_level, replace

twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess estimate year if class==4 & ed_level==2, sort lpattern (dash) lcolor(black)) (lowess estimate year if class==5 & ed_level==1, sort lpattern (dash) lcolor(gray)), graphregion(color(white)) legend(order(1 "upper-middle class" 2 "Skilled working class" 3 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path.dta\output\DE_margins_lowessINCOME.png", replace


*CH
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level income if COUNTRY==756 & AGE>=20 & AGE<=60
margins class5#ed_level, at(AGE=40 SEX01=1) atmeans by (YEAR) post

parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates", replace)

use "$path.dta\temporary estimates", clear

br

split parm, p("." "#")
rename parm1 year
destring year, replace
rename parm3 class5
destring class5, replace
rename parm5 ed_level
destring ed_level, replace

twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess estimate year if class==4 & ed_level==2, sort lpattern (dash) lcolor(black)) (lowess estimate year if class==5 & ed_level==1, sort lpattern (dash) lcolor(gray)), graphregion(color(white)) legend(order(1 "upper-middle class" 2 "Skilled working class" 3 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path.dta\output\CH_margins_lowessINCOME.png", replace


*SE
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level income if COUNTRY==752 & AGE>=20 & AGE<=60
margins class5#ed_level, at(AGE=40 SEX01=1) atmeans by (YEAR) post

parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates", replace)

use "$path.dta\temporary estimates", clear

br

split parm, p("." "#")
rename parm1 year
destring year, replace
rename parm3 class5
destring class5, replace
rename parm5 ed_level
destring ed_level, replace

twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess estimate year if class==4 & ed_level==2, sort lpattern (dash) lcolor(black)) (lowess estimate year if class==5 & ed_level==1, sort lpattern (dash) lcolor(gray)), graphregion(color(white)) legend(order(1 "upper-middle class" 2 "Skilled working class" 3 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path.dta\output\SE_margins_lowessINCOME.png", replace


*NO
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level income if COUNTRY==578 & AGE>=20 & AGE<=60
margins class5#ed_level, at(AGE=40 SEX01=1) atmeans by (YEAR) post

parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates", replace)

use "$path.dta\temporary estimates", clear

br

split parm, p("." "#")
rename parm1 year
destring year, replace
rename parm3 class5
destring class5, replace
rename parm5 ed_level
destring ed_level, replace

twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess estimate year if class==4 & ed_level==2, sort lpattern (dash) lcolor(black)) (lowess estimate year if class==5 & ed_level==1, sort lpattern (dash) lcolor(gray)), graphregion(color(white)) legend(order(1 "upper-middle class" 2 "Skilled working class" 3 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path.dta\output\NO_margins_lowessINCOME.png", replace


*PO
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level income if COUNTRY==616 & AGE>=20 & AGE<=60
margins class5#ed_level, at(AGE=40 SEX01=1) atmeans by (YEAR) post

parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates", replace)

use "$path.dta\temporary estimates", clear

br

split parm, p("." "#")
rename parm1 year
destring year, replace
rename parm3 class5
destring class5, replace
rename parm5 ed_level
destring ed_level, replace

twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess estimate year if class==4 & ed_level==2, sort lpattern (dash) lcolor(black)) (lowess estimate year if class==5 & ed_level==1, sort lpattern (dash) lcolor(gray)), graphregion(color(white)) legend(order(1 "upper-middle class" 2 "Skilled working class" 3 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path.dta\output\PO_margins_lowessINCOME.png", replace


*HU
estimate clear
clear
use "$path\DATASET_1987-2018_ready.dta"

quietly reg TOPBOT100 class5##YEAR i.SEX01 AGE i.ed_level income if COUNTRY==348 & AGE>=20 & AGE<=60
margins class5#ed_level, at(AGE=40 SEX01=1) atmeans by (YEAR) post

parmest, format (estimate min95 max95 %8.3f p %8.1e) saving ("$path.dta\temporary estimates", replace)

use "$path.dta\temporary estimates", clear

br

split parm, p("." "#")
rename parm1 year
destring year, replace
rename parm3 class5
destring class5, replace
rename parm5 ed_level
destring ed_level, replace

twoway (lowess estimate year if class==1 & ed_level==3, sort lpattern (solid) lcolor(black))(lowess estimate year if class==4 & ed_level==2, sort lpattern (dash) lcolor(black)) (lowess estimate year if class==5 & ed_level==1, sort lpattern (dash) lcolor(gray)), graphregion(color(white)) legend(order(1 "upper-middle class" 2 "Skilled working class" 3 "Unskilled working class") nobox region(lstyle(none))) yscale(range(30 70)) xscale(range(1987 2017) noextend) xlabel(1987(5)2017) ylabel(30(10)70, nogrid) ytitle("") xtitle("")
graph export "$path.dta\output\HU_margins_lowessINCOME.png", replace


********************************************************************************
*Table W.4: linear regression on the subjective status of respondents' job compared to the perceived status of their father’s job when they were 16 (on a scale from 0 to 100)

clear
use "$path.dta\DATASET_1987-2018_ready.dta"

gen V67_100=V67
recode V67_100 (5=0) (4=25) (3=50) (2=75)(1=100) 

gen period=.
replace period=1 if YEAR>=1987 & YEAR<=1992
replace period=2 if YEAR==1999
replace period=3 if YEAR==2009 | YEAR==2010

tab YEAR period, m

label define period 1 "1987-1999" 2 "1999" 3 "2009"
label values period period

local country 840
foreach i of local country {
quietly reg V67_100 class5##period SEX01 AGE if COUNTRY==`i' & AGE>=20 & AGE<=60
outreg2 using regression_interactions.xls, replace ctitle(model `i') dec(2)
}


local country 82601 752 578 276 756 616 348
foreach i of local country {
quietly reg V67_100 class5##period SEX01 AGE if COUNTRY==`i' & AGE>=20 & AGE<=60
outreg2 using regression_interactions.xls, append ctitle(model `i') dec(2)
}
